﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using ENTIDADES;

namespace DATA
{
    public  class dComprobante
    {
        public void GuardarOModificar(eComprobante c, string oper)
        {
            
            Conexion strCNN = new Conexion();
            SqlConnection cn = new SqlConnection(strCNN.obtenerConexion() );           
            SqlTransaction trans = null;

            try
            {
                cn.Open();
                trans = cn.BeginTransaction();

                SqlCommand cmd = new SqlCommand("insertComprobante", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Transaction = trans;               
                cmd.Parameters.AddWithValue("@idcomprobante", c.idcomprobante);
                cmd.Parameters.AddWithValue("@idpedido", c.idpedido);
                cmd.Parameters.AddWithValue("@fecha", c.fecha);
                cmd.Parameters.AddWithValue("@total", c.total);
                cmd.Parameters.AddWithValue("@subtotal", c.subtotal);
                cmd.Parameters.AddWithValue("@totaligv", c.totaligv);
                cmd.Parameters.AddWithValue("@idmesa", c.idmesa);                
                cmd.Parameters.AddWithValue("@idtipocomprobante", c.idtipocomprobante);                
                cmd.Parameters.AddWithValue("@oper", oper);                
                cmd.ExecuteNonQuery();
                trans.Commit();
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}
